const mongoose = require('mongoose');

mongoose.Promise = global.Promise;

mongoose.set('debug', true);

function connectMongoDB() {
  mongoose.connect('mongodb://localhost:27017/chat_test', {
    useNewUrlParser: true,
    useCreateIndex: true,
    useUnifiedTopology: true
  });

  mongoose.connection.on('error', () => {
    console.log('MongoDB Connected error...');
  });

  mongoose.connection.on('disconnected', () => {
    console.log(`MongoDB Disconnected...`);
  });

  mongoose.connection.once('open', () => {
    console.log(`MongoDB Connected Successfully...`);
  });

  require('./models/chats');
  require('./models/users');
}

module.exports = connectMongoDB;
